package com.qf.bank.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.bank.cardinfoapi.api.CardInfoApi;
import com.qf.bank.cardinfoapi.po.CardInfo;
import com.qf.bank.cardinfoapi.vo.CardInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Create on 2019/12/5 15:31
 *
 * @author 飞
 */
@Slf4j
@RestController
@RequestMapping("/cardInfo")
public class CardInfoController {

    @Resource
    private CardInfoApi cardInfoApi;

    /**
     * 分页查询   银行卡
     * @param cardInfoVo
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public Page<CardInfo> page(CardInfoVo cardInfoVo){
        Page<CardInfo> page = cardInfoApi.page(cardInfoVo);
        return page;
    }

    /**
     * 根据用户名获取用户所有的银行卡信息
     * @param userName
     * @return
     */
    @RequestMapping(value = "/name", method = RequestMethod.GET)
    public List<CardInfo> getByuserName(@RequestParam String userName){
        List<CardInfo> byuserName = cardInfoApi.getByuserName(userName);
        return byuserName;
    }


    /**
     * 添加一个银行卡信息
     * @param cardInfo
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public Boolean getInsert(@RequestBody CardInfo cardInfo){
        Boolean insert = cardInfoApi.getInsert(cardInfo);
        return insert;
    }

    /**
     * 根据银行卡id删除一条银行卡信息
     * @param cardId
     * @return
     */
    @RequestMapping(value = "/{cardId}", method = RequestMethod.DELETE)
    public Boolean deleteById(@PathVariable(value = "cardId") int cardId){
        Boolean aBoolean = cardInfoApi.deleteById(cardId);
        return aBoolean;
    }

    /**
     * 根据银行卡id修改一条银行卡信息
     * @param cardInfo
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    public Boolean updateById(@RequestBody CardInfo cardInfo){
        Boolean aBoolean = cardInfoApi.updateById(cardInfo);
        return aBoolean;
    }
}
